version: "3.9"

services:
  api:
    container_name: atox_login.api
    build: .
    command: [ "python", "-Om", "src.api" ]
    restart: unless-stopped
    networks:
      - atox_login.postgres.network
      - atox_login.redis.network
    ports:
      - "1000:8071"
    depends_on:
      postgres:
        condition: service_healthy
  postgres:
    container_name: atox_login.postgres
    image: "postgres:15-alpine"
    hostname: atox_login.postgres
    restart: unless-stopped
    expose:
      - "5432"
    ports:
      - "127.0.0.1:15432:5432"
    networks:
      - atox_login.postgres.network
    environment:
      POSTGRES_PASSWORD: $DB__PASSWORD
      POSTGRES_USER: ${DB__USER:-$USER}
      POSTGRES_DB: ${DB__NAME:-$USER}
    volumes:
      - atox_login.postgres.data:/var/lib/postgresql/data:rw
    healthcheck:
      test: [ "CMD-SHELL", "pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}" ]
      interval: 10s
      timeout: 60s
      retries: 5
      start_period: 10s
  postgres-migration:
    container_name: atox_login.postgres_migration
    build:
      context: .
    restart: on-failure
    depends_on:
      postgres:
        condition: service_healthy
    networks:
      - atox_login.postgres.network
    volumes:
      - ./alembic.ini:/app/alembic.ini:ro
      - ./src/database/migrations:/app/src/database/migrations:ro
    command: ["python", "-m", "alembic", "upgrade", "head"]
  redis:
    container_name: atox_login.redis
    restart: always
    image: "redis:7.2.3-alpine"
    ports:
      - "6331:6379"
    networks:
      - atox_login.redis.network
    volumes:
      - atox_login.redis.data:/var/lib/redis/data

volumes:
  atox_login.postgres.data: { }
  atox_login.redis.data: {}

networks:
  atox_login.postgres.network: {}
  atox_login.redis.network: {}